package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.MemberOrganizationAddVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.MemberOrganizationDeleteVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.MemberOrganizationGetVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.request.MemberOrganizationUpdateVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.MemberOrgTreeVO;
import com.ssy.lingxi.member.merchant.model.vo.maintenance.response.MemberOrganizationQueryVO;
import com.ssy.lingxi.member.merchant.service.web.IMemberAbilityOrganizationService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 系统能力 - 权限管理 - 组织机构管理
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-29
 */
@RestController
@RequestMapping("/member/org")
public class MemberAbilityOrganizationController {

    @Resource
    private IMemberAbilityOrganizationService memberAbilityOrganizationService;

    /**
     * 新增会员组织架构菜单
     * @param headers  HttpHeaders信息
     * @param addVO 接口参数
     * @return 新增结果
     */
    @RequestMapping("/add")
    public Wrapper<Void> addMemberOrg(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberOrganizationAddVO addVO) {
        return memberAbilityOrganizationService.addMemberOrg(headers, addVO);
    }

    /**
     * 根据菜单Id，更新组织机构信息
     * @param headers HttpHeaders信息
     * @param updateVO 接口参数
     * @return 更新结果
     */
    @RequestMapping("/update")
    public Wrapper<Void> updateMemberOrg(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberOrganizationUpdateVO updateVO) {
        return memberAbilityOrganizationService.updateMemberOrg(headers, updateVO);
    }

    /**
     * 删除一个组织机构信息
     * @param headers HttpHeaders信息
     * @param deleteVO 接口参数
     * @return 删除结果
     */
    @RequestMapping("/delete")
    public Wrapper<Void> deleteMemberOrg(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberOrganizationDeleteVO deleteVO) {
        return memberAbilityOrganizationService.deleteMemberOrg(headers, deleteVO);
    }

    /**
     * 查询一个组织机构信息
     * @param headers HttpHeaders信息
     * @param getVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public Wrapper<MemberOrganizationQueryVO> getMemberOrg(@RequestHeader HttpHeaders headers, @Valid MemberOrganizationGetVO getVO) {
        return memberAbilityOrganizationService.getMemberOrg(headers, getVO);
    }

    /**
     * 查询所有组织机构信息，以树形菜单的形式返回
     * @param headers HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/tree", method = RequestMethod.GET)
    public Wrapper<List<MemberOrgTreeVO>> getMemberOrgTreeByMemberId(@RequestHeader HttpHeaders headers) {
        return memberAbilityOrganizationService.treeMemberOrg(headers);
    }

    /**
     * 查询会员的（非门店）所有组织架构，以树形菜单的形式返回
     * @param headers HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/non/store/tree", method = RequestMethod.GET)
    public Wrapper<List<MemberOrgTreeVO>> nonStoreTreeMemberOrg(@RequestHeader HttpHeaders headers){
        return memberAbilityOrganizationService.nonStoreTreeMemberOrg(headers);
    }
}
